<template>
	<view class="flex-colume-start infoPage">
		<view class="flex-colume-start mine-bg">
			<view style="margin-top: 74rpx; position: relative;">
				<image class="photo1" :src="userModel.avatar"></image>
				<image @click="photoBtnClick()" src="/static/mine/add-red.png" class="addBtn"></image>
			</view>
			<view style="margin-top: 25rpx; font-size: 28rpx; color: #0A1E3C;" @click="itemClick('nickname')">{{userModel.nickname}}</view>
			<view class="flex-colume-start infoBox">
				<!-- <view class="flex-row-start item1">
					<view class="desc1">
						<span class="redText">*</span>真实姓名
					</view>
					<view class="desc2" @click="itemClick('username')">{{userModel.username}}</view>
				</view> -->
				<view class="flex-row-start item1">
					<view class="desc1">
						所在城市
					</view>
					<view class="desc2"></view>
				</view>
				<!-- <view class="flex-row-start item1">
					<view class="desc1">
						<span class="redText">*</span>手机号
					</view>
					<view class="desc2" @click="itemClick('mobile')">{{userModel.mobile}}</view>
				</view> -->
				<!-- <view class="flex-row-start item1">
					<view class="desc1">
						微信号
					</view>
					<view class="desc2"></view>
				</view>
				<view class="flex-row-start item1">
					<view class="desc1">
						<span class="redText">*</span>微信二维码
					</view>
					<view class="desc2"></view>
				</view> -->
				<view class="flex-row-start item1">
					<view class="desc1">
						收件地址
					</view>
					<view class="desc2" @click="itemClick('adr')">点击选择</view>
				</view>
				<view class="flex-row-start item1">
					<view class="desc1">
						注册时间
					</view>
					<view class="desc2"></view>
				</view>
			</view>
		</view>
		<AdrList ref="AdrList"></AdrList>
		<u-popup mode='bottom' :show="open1" :overlay="true" :closeable="false" :round="15"
			:closeOnClickOverlay="true" @close="open1 = false">
			<view class="flex-colume-start userInfoSetBox">
				<view style="font-size: 30rpx; font-weight: 500;">{{alert.title}}</view>
				<view class="flex-row-center input1">
					<input v-model="inputText1" :placeholder="alert.place"></input>
				</view>
				<view class="flex-row-center user-btn-box">
					<view class="b0" @click="open1 = false">取消</view>
					<view class="b0 b1" @click="sureBtnClick()">保存</view>
				</view>
			</view>
		</u-popup>


	</view>
</template>

<script>
	import {
		userInfo,
		uploadImgUrl,
		editUserInfo
	} from '@/api/api'

	import AdrList from '@/components/adrList/adrList.vue';


	export default {
		components: {
			AdrList

		},
		data() {
			return {
				open1:false,
				inputText1:'',
				alert:{
					title:'',
					place:''
				},
				userModel: {

				}


			}
		},
		onLoad() {
			this.requestInfo()

		},
		methods: {
			itemClick(e) {
				this._selCell = e
				if (e == 'adr') {
					this.$refs.AdrList.init()
				}
				if (e == 'username') {
					this.open1 = true
					this.alert = {
						title:'设置真实姓名',
						place:'您的真实姓名'
					}
				}
				if (e == 'nickname') {
					this.open1 = true
					this.alert = {
						title:'设置昵称',
						place:'您的昵称'
					}
				}
				if (e == 'mobile') {
					this.open1 = true
					this.alert = {
						title:'设置手机号',
						place:'您的手机号'
					}
				}

			},
			photoBtnClick() {
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success: res => {
						var path = res.tempFilePaths[0]
						this.uploadImg(path)
					}

				})
			},
			sureBtnClick(){
				if (!this.inputText1){
					this.showSimpleMessage(this.alert.title)
					return
				}
				if (this._selCell == 'username'){
					uni.showLoading({
						mask:true
					})
					this.requestUptInfo({username:this.inputText1})
				}
				if (this._selCell == 'nickname'){
					uni.showLoading({
						mask:true
					})
					this.requestUptInfo({nickname:this.inputText1})
				}
				if (this._selCell == 'mobile'){
					uni.showLoading({
						mask:true
					})
					this.requestUptInfo({mobile:this.inputText1})
				}
				
			},

			requestInfo() {
				userInfo().then(res => {
					if (res.code == 200) {
						this.userModel = res.data.info
					}
				})
			},
			requestUptInfo(params) {
				editUserInfo(params).then(res => {
					if (res.code == 200) {
						this.requestInfo()
					}
					this.showSimpleMessage(res.message)

					setTimeout(res => {
						uni.hideLoading()
					}, 2000)
				})
			}


		}
	}
</script>
<style>
	page {
		background-color: white;
	}
</style>

<style lang="scss" scoped>
	.infoPage {
		font-size: 0px;

		.photo1 {
			width: 211rpx;
			height: 211rpx;
			border-radius: 211rpx;
			border: 1px solid white;
			background-color: rgb(230, 230, 230);
		}

		.addBtn {
			position: absolute;
			left: 140rpx;
			top: 170rpx;
			width: 48rpx;
			height: 48rpx;
			box-sizing: border-box;
			padding: 5rpx;

		}

		.infoBox {
			margin-top: 50rpx;
			width: 670rpx;
			background-color: white;
			border-radius: 16rpx;
			padding: 10rpx 16rpx;
			box-sizing: border-box;

			.item1 {
				height: 80rpx;
				width: 100%;
				justify-content: space-between;
				border-bottom: 1px solid rgb(230, 230, 230);

				.desc1 {
					font-family: PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #0A1E3C;

					.redText {
						color: #C90000;
					}

				}

				.desc2 {
					font-size: 24rpx;
					color: rgb(153, 153, 153);
				}
			}

			.item1:last-child {
				border-bottom: 1px solid rgba(230, 230, 230, 0);
			}
		}
	}

	.mine-bg {
		width: 750rpx;
		// height: 519rpx;
		background: url('https://app.yiheshuyuan.cn/static/weixin/xcxPic/mine-bg1.png');
		background-size: 100% 519rpx;
		background-repeat: no-repeat;
	}
	.userInfoSetBox{
		background-color: white;
		padding-top: 50rpx;
		padding-bottom: calc(env(safe-area-inset-bottom) + 40rpx);
		
		.input1{
			margin-top: 30rpx;
			width: 550rpx;
			height: 80rpx;
			border-radius: 100rpx;
			border: 1px solid rgb(230, 230, 230);
			padding: 0rpx 40rpx;
			box-sizing: border-box;
			input{
				width: 100%;
				font-size: 26rpx;
			}
		}
		
		.user-btn-box .b0{
			margin-top: 40rpx;
			width: 250rpx;
			height: 70rpx;
			line-height: 70rpx;
			border: 1px solid #C90000;
			color: #C90000;
			font-size: 28rpx;
			text-align: center;
			border-radius: 100rpx;
		}
		.user-btn-box .b1{
			margin-left: 50rpx;
			
			color: white;
			background-color: #C90000;
			
		}
		
		
	}
</style>